export default {
    namespaced: true,
    state: {
      userAvatar: uni.getStorageSync("userAvatar") || "",
      nickName: uni.getStorageSync("nickName") || "",
      token: uni.getStorageSync("token") || "",
    },
    mutations: {
      updateUserAvatar(state, payload) {
        state.userAvatar = payload;
        uni.setStorageSync("userAvatar", payload);
      },
      updateNickName(state, payload) {
        state.nickName = payload;
        uni.setStorageSync("nickName", payload);
      },
      updateToken(state, payload) {
        state.token = payload;
        uni.setStorageSync("token", payload);
      },
    },
    actions: {
      async wxLoginAction(context) {
        const [error, res] = await uni.getUserInfo();
        // console.log(res);
        const { encryptedData, iv, rawData, signature } = res;
  
        const [error2, { code }] = await uni.login();
        // console.log(res2);
        const data = {
          encryptedData,
          iv,
          rawData,
          signature,
          code,
        };
        console.log(data);
        const res2 = await uni.$u.http.post("/users/wxlogin", data);
        // console.log(res2);
        // console.log(res2.data.message.token);
        const token = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIxMywiaWF0IjoxNjcxOTQwNDUwLCJleHAiOjEwMDE2NzE5NDA0NDl9.Rus33a3QCI0tyoJohug9jQ4gI-vf3bAFe6nBJrsb_GY'
        context.commit("updateToken", token);
      },
    },
  };